package bysj.service;

import bysj.dao.GraduateProjectTruenessDao;
import bysj.domain.GraduateProjectTrueness;
import util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;

public class GraduateProjectTruenessService {
    private static GraduateProjectTruenessDao graduateProjectTruenessDao= GraduateProjectTruenessDao.getInstance();
    private static GraduateProjectTruenessService graduateProjectTruenessService=new GraduateProjectTruenessService();
    private GraduateProjectTruenessService(){}

    public static GraduateProjectTruenessService getInstance(){
        return graduateProjectTruenessService;
    }

    public GraduateProjectTrueness find(Integer id) throws SQLException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        GraduateProjectTrueness graduateProjectTrueness=null;
        //将自动提交设为false,开始事务
        connection.setAutoCommit(false);
        try {
            graduateProjectTrueness=graduateProjectTruenessDao.find(id,connection);
            //提交事务
            connection.commit();
        }catch (SQLException e) {
            //回滚事务中所有操作
            connection.rollback();
        } finally {
            //将自动提交设置为true，结束事务
            connection.setAutoCommit(true);
            //关闭连接
            JdbcHelper.close(connection);
        }
        return graduateProjectTrueness;
    }
}
